package com.example.smartlearning.controller;

import com.example.smartlearning.service.impl.TieZiServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@CrossOrigin//跨域
@RestController//遵循RestFul
@RequestMapping("/Smart/TieZi/")
public class TieZiController {
    @Resource
    TieZiServiceImpl tieZiService;

    /**
     * 获取所有帖子
     *
     * @return 返回
     */
    @GetMapping("getAll")
    public String getAll() {
        return tieZiService.getAll();
    }

    /**
     * 根据关键词获取帖子
     *
     * @param keyWord 关键词
     * @return 返回
     */
    @GetMapping("getByKeyWord")
    public String getByKeyWord(@RequestParam("keyWord") String keyWord) {
        return tieZiService.getByKeyWord(keyWord);
    }

    /**
     * 新增帖子
     *
     * @param title   标题
     * @param content 内容
     * @param userId  用户id
     * @return 返回
     */
    @PutMapping("addNew")
    public String addNew(
            @RequestParam("title") String title,
            @RequestParam("content") String content,
            @RequestParam("userId") int userId,
            @RequestParam("keyWord") String keyWord
    ) {
        return tieZiService.addNew(title, content, userId, keyWord);
    }

    /**
     * 删除帖子
     *
     * @param id id
     * @return 返回
     */
    @PostMapping("deleteById")
    public String getByKeyWord(@RequestParam("id") int id) {
        return tieZiService.deleteById(id);
    }

    /**
     * 点赞接口
     *
     * @param id id
     * @return 返回
     */
    @PostMapping("updateTzUpvote")
    public String updateTzUpvote(@RequestParam("id") int id) {
        return tieZiService.updateTzUpvote(id);
    }

    /**
     * 取消点赞
     *
     * @param id id
     * @return 取消
     */
    @PostMapping("cancelTzUpvote")
    public String cancelTzUpvote(@RequestParam("id") int id) {
        return tieZiService.cancelTzUpvote(id);
    }
}
